//
//  YsSmartPenInitManager.m
//  YsSmartPenCoreModule
//
//  Created by Cer on 2020/4/21.
//

#import "YsSmartPenInitManager.h"
#import <YYKit/YYKit.h>
#import <YsToolsManager/YsToolsManager.h>
#import <YsRealmTools/YsRealmTools.h>

@implementation YsSmartPenInitManager

+ (void)cacheWithDic:(NSDictionary<NSString *,NSString *> *)dic
{
    YYCache *cache = [YYCache cacheWithPath:[YsToolsManagerFileUtil.getLibraryCachePath stringByAppendingPathComponent:@"YsSmartPenCoreModule/YYCache"]];
    [cache setObject:dic forKey:@"externalInformation"];
    [self initRealmData];
}

+ (void)initRealmData
{
    /// 初始化数据库
    [self setupConfigWithPath:[YsToolsManagerFileUtil.getLibraryCachePath stringByAppendingPathComponent:@"YsSmartPenCoreModule/Realm"] withRealmName:@"SmartPen.realm"];
    /// 初始化数据库
}

+ (void)setupConfigWithPath:(NSString *)path
                 withRealmName:(NSString *)realmName {
    [YsToolsManagerFileUtil createDirectory:path];
    NSString *realmPath = [path stringByAppendingPathComponent:realmName];
    RLMRealmConfiguration * config = [RLMRealmConfiguration defaultConfiguration];
    config.schemaVersion = 1;
    config.fileURL = [NSURL URLWithString:realmPath];
    config.migrationBlock = ^(RLMMigration * _Nonnull migration, uint64_t oldSchemaVersion) {
        if (oldSchemaVersion < 1) {
            NSLog(@"进行数据迁移");
        }else{
            NSLog(@"不进行数据迁移");
        }
    };
    [RLMRealmConfiguration setDefaultConfiguration:config];
    [RLMRealm defaultRealm];
}
@end
